<template>
    <div>
        <el-badge :value="value"  class="a">
            <el-button type="primary" @click="request">骑手提现请求</el-button>
        </el-badge>
        <br>
        <el-button type="primary" class="a" @click="queryFinish">查看提现完成</el-button>

        <!--未体现-->
        <el-dialog
                title="骑手体现请求"
                :visible.sync="dialogVisible"
                width="70%"
                :before-close="handleClose">
            <template>
                <el-table
                        :data="tableData"
                        border
                        height="500px"
                        style="width: 80%">
                    <el-table-column
                            prop="rider.name"
                            label="提现人"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="startTime"
                            label="提现时间"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="money"
                            label="提现金额"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            label="操作"
                            width="180">
                        <template slot-scope="scope">
                            <template>
                                <el-popconfirm
                                        title="确认提现?"
                                        @confirm="finish(scope.row.id)"
                                >
                                    <el-button  slot="reference" type="primary" size="small">完成提现</el-button>
                                </el-popconfirm>
                            </template>

                        </template>
                    </el-table-column>
                </el-table>
            </template>
        </el-dialog>

        <!--查看已提现-->
        <el-dialog
                title="提现记录"
                :visible.sync="dialogVisible1"
                width="70%"
                :before-close="handleClose">
            <template>
                <el-table
                        :data="tableData1"
                        border
                        height="500px"
                        style="width: 80%">
                    <el-table-column
                            prop="rider.name"
                            label="提现人"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="startTime"
                            label="提现时间"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="endTime"
                            label="完成提现时间"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="money"
                            label="提现金额"
                            width="180">
                    </el-table-column>
                </el-table>
            </template>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "Money",
    data() {
        return {
            value:"",
            dialogVisible:false,
            dialogVisible1:false,
            tableData:[],
            tableData1:[],
        }
    },
    mounted() {
        this.init();
    },
    methods: {
        init() {
            this.axios.get("back/withdraw/count").then(
                r => {
                    this.value = r.data;
                }
            )
        },
        request() {
            this.dialogVisible = true;
            this.axios.get("back/withdraw/withdraw",{params:{num:0}}).then(
                r => {
                    this.tableData = r.data;
                }
            )
        },
        finish(id){
            let formData = new FormData();
            formData.append("id",id);
            this.axios.post("back/withdraw/finish",formData).then(
                r =>{
                    if (r.data == "no"){
                        this.$message.error('提现失败');
                    }else if (r.data == "ok"){
                        this.$message.success('提现成功');
                        this.request();
                        this.init();
                    }
                }
            );
        },
        queryFinish(){
            this.dialogVisible1 = true;
            this.axios.get("back/withdraw/withdraw",{params:{num:1}}).then(
                r => {
                    this.tableData1 = r.data;
                }
            )
        }
    }
}
</script>

<style scoped>
    .a{
        margin: 30px 30px 30px 30px ;
    }
</style>